package com.dwxt.parabolic.config;

import com.dwxt.parabolic.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                //添加需要验证登录用户操作权限的请求
                .addPathPatterns("/**")
                //这里add为“/**”,下面的exclude才起作用，且不管controller层是否有匹配客户端请求，拦截器都起作用拦截
//                .addPathPatterns("/hello")
                //如果add为具体的匹配如“/hello”，下面的exclude不起作用,且controller层不匹配客户端请求时拦截器不起作用

                //排除不需要验证登录用户操作权限的请求
                .excludePathPatterns("/parabolic/user/login", "/parabolic/event/add", "/parabolic/list/all",
                        "/parabolic/file/saveEventFile","/parabolic/authentication/wx","/parabolic/event/selectById");
        //这里可以用registry.addInterceptor添加多个拦截器实例，后面加上匹配模式
        //super.addInterceptors(registry);//最后将register往这里塞进去就可以了
    }
}
